import turtle
turtle.tracer(False)
red_pos=[-360,0]
blue_pos=[343,0]
dot_pos=[0,0]
h = 0
def goto(pos):
    turtle.up()
    turtle.goto(pos)
    turtle.down()

def dot_move():
    global h
    if  dot_pos[0]<-330:
        if dot_pos[1]==red_pos[1]:
            h=0
    elif dot_pos[0] > 330:
        if dot_pos[1]==blue_pos[1]:
            h = 180

    if h==0:
        dot_pos[0]+=20
    elif h==180:
        dot_pos[0]-=20


def board():
    turtle.clear()
    dot_move()
    goto(dot_pos)
    turtle.dot(30,'black')
    goto(red_pos)
    turtle.fillcolor("red")
    turtle.begin_fill()
    for i in range(2):
        turtle.forward(10)
        turtle.right(90)
        turtle.forward(50)
        turtle.right(90)
    turtle.end_fill()
    goto(blue_pos)
    turtle.fillcolor("blue")
    turtle.begin_fill()
    for i in range(2):
        turtle.forward(10)
        turtle.right(90)
        turtle.forward(50)
        turtle.right(90)
    turtle.end_fill()
    turtle.ontimer(board,100)
board()
def red_up():
    red_pos[1]+=20
def red_down():
    red_pos[1]-=15
turtle.onkeypress(red_up,"w")
turtle.onkeypress(red_down, "s")


def blue_up():
    blue_pos[1]+=20
def blue_down():
    blue_pos[1]-=15
turtle.onkeypress(blue_up,"Up")
turtle.onkeypress(blue_down,"Down")

turtle.listen()
turtle.done()
